#pragma once

#include "PhysicsPrimitives.h"
#include "Array.h"

namespace mphys
{
	class CollisionData;

	class PhysicsSystem
	{
	public:
		PhysicsSystem();
		~PhysicsSystem();

		

		RigidBody & createBoxRigidBody(RigidBody::ID id = INCORRECT_RB_ID);
		RigidBody & createSphereRigidBody(RigidBody::ID id = INCORRECT_RB_ID);
		RigidBody & createPlaneRigidBody(RigidBody::ID id = INCORRECT_RB_ID);

		RigidBody & createBoxCopy(const Box & src);
		RigidBody & createSphereCopy(const Sphere & src);
		RigidBody & createPlaneCopy(const Plane & src);

		RigidBody & findRigidBody(RigidBody::ID id);
		void removeRigidBody(RigidBody & rb);

		void update(float dt);

	private:
		void addToRigidBodyMap(RigidBody & rb, RigidBody::ID id = INCORRECT_RB_ID);
		void updateRigidBodyMapEntry(RigidBody & rb);
		void removeRigidBodyMapEntry(RigidBody & rb);

		util::Array<Box> mBoxes;
		util::Array<Sphere> mSpheres;
		util::Array<Plane> mPlanes;

		std::map<RigidBody::ID, RigidBody*> mRigidBodies;
		static const RigidBody::ID INCORRECT_RB_ID = 0;
		RigidBody::ID mNextID;

		CollisionData * mCollData;
	};
}